package cn.gzjp.modules.woms.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;
//import org.hibernate.validator.constraints.Length(min=0, max=256, message="角色;

import cn.gzjp.common.persistence.DataEntity;
import cn.gzjp.common.utils.excel.annotation.ExcelField;

import java.util.Arrays;
import java.util.List;

/**
 * 工作人员Entity
 * @author liyp
 * @version 2018-07-07
 */
public class Worker extends DataEntity<Worker> {
	
	private static final long serialVersionUID = 1L;
	private String mobile;		// 手机号
	private String name;		// 名称
	private String sex;		// 性别
	private String headImg;   //头像
	private String roles;		// 角色(项目管理员、外场管理员、外出运维人员)

	private String projects;		// 关联项目(多个，)
	private String projectsStr;		// 冗余汉字关联项目(多个，)


	private String projectId;//用于查询；

	private String password;

	
	public Worker() {
		super();
	}

	public Worker(String id){
		super(id);
	}

	@Length(min=0, max=11, message="手机号长度必须介于 0 和 11 之间")
	@ExcelField(title="手机号", align=2, sort=1)
	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	
	@Length(min=0, max=256, message="名称长度必须介于 0 和 256 之间")
	@ExcelField(title="名称", align=2, sort=2)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Length(min=0, max=1, message="性别长度必须介于 0 和 1 之间")
	@ExcelField(title="性别", align=2, sort=3)
	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}
	
	@Length(min=0, max=256, message="角色(项目管理员、外场管理员、外出运维人员)长度必须介于 0 和 256 之间")
	@ExcelField(title="角色(项目管理员、外场管理员、外出运维人员)", align=2, sort=4)
	public String getRoles() {
		return roles;
	}

	public String getHeadImg() {
		return headImg;
	}

	public void setHeadImg(String headImg) {
		this.headImg = headImg;
	}

	public void setRoles(String roles) {
		this.roles = roles;

	}

	@JsonIgnore
	public List<String> getProjectsList() {
		String projects[] = {};
		if(StringUtils.isNotBlank(this.getProjects())){
			projects =this.getProjects().split(",");
		}
		return Arrays.asList(projects);
	}

	public void setProjectsList(List<String> projectsList) {
		projects = "";
		for (String st : projectsList) {
			projects+=st+",";
		}
		if(projects!=null&&projects.length()>0){
			projects = projects.substring(0, projects.length()-1);
		}
	}

	public String getProjects() {
		return projects;
	}

	public void setProjects(String projects) {
		this.projects = projects;
	}

	public String getProjectsStr() {
		return projectsStr;
	}

	public void setProjectsStr(String projectsStr) {
		this.projectsStr = projectsStr;
	}

	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
}